<?php

namespace App\Controllers;

use Framework\Database;

class ListingController
{
  protected $db;

public function _construct()
{
  $config = require basePath('config/db.php');
  $this->db = new Database($config);
}
public function index(){
  $listings = $this->db->query('SELECT * FROM listing')->fetchAll();

  loadView('home',[
    'listings'=> $listings
    ]);
}

public function create()
{
  loadView('listings/create');
}

public function show()
{
  $id = $_GET['id'] ??'';
  $parans =[
    'id'=> $id
  ];

  $listing = $this->db->query('SELECT * FROM listing WHERE id = :id', $params)->fetch();

  loadView('listings/show',[
    'listing'=> $listing
  ]);

}

}
